#include <stdio.h>
#include <stdlib.h>
struct student {
	char num[20];
	char name[12];
	int score[3];
	int sum;
}
stu[5];
int main(void) {
	int i,j;
	char ch;
	FILE *fp;
	for (i=0;i<5;i++) {
		printf("\n 第 %d 个学生",i+1);
		printf("\n学号：");
		scanf("%s",stu[i].num);
		printf("姓名：");
		scanf("%s",stu[i].name);
		stu[i].sum=0;
		for (j=0;j<3;j++) {
			printf("分数%d :",j+1);
			scanf("%d",&stu[i].score[j]);
			stu[i].sum+=stu[i].score[j];
		}
	}
	if((fp = fopen("stu.txt", "w"))==NULL){
		puts("打开文件时出现错误");
		exit(0);
	}
	for(i=0;i<5;i++) {
		fprintf(fp,"%s %s %d %d %d %d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum);
	}
	fclose(fp);
	fp = fopen("stu.txt", "r");
	ch = fgetc(fp);
	while (ch != EOF)
	{
		printf("%c", ch);
		ch = fgetc(fp);
	}
	printf("\n");
	fclose(fp);
}
